<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2-CORS</title>
</head>
<body>
    <button id="btn">发ajax请求</button>
    <script>
        document.querySelector('#btn').onclick = ()=>{
            const xhr = new XMLHttpRequest()
            xhr.open('get','http://127.0.0.1:3014/origin-server')
            xhr.send()
            xhr.onreadystatechange  = ()=>{
                if(xhr.readyState === 4){
                    if(xhr.status >= 200 && xhr.status <= 299){
                        alert('请求成功:'+xhr.responseText)
                    }else{
                        alert('请求失败:'+xhr.status)
                    }
                }
            }
        }





    </script>
</body>
</html>